import Vue from "vue";
import Vuex from 'vuex'
import ajax from '../service/ajax'


Vue.use(Vuex)

export default new Vuex.Store({
    state(){
        return{
            loginUser:'',
            isLogin:false,
            count:100
        }

    },
    mutations:{
        setLoginUser(state,user){
            state.loginUser = user
        },
        setLoginStatus(state,boo){
            state.isLogin = boo
        }
    },
    getters:{
        getLoginUser(state){
            return state.loginUser
        },
        isLogin(state){
            return state.isLogin
        },
        getCount(state){
            return state.count 
        }
    },
    actions:{
        async login(context,payload){
            // console.log(payload) 
            let params = {
                'userName':payload.userName,
                'userPwd':payload.userPwd
            }
            console.log(params.userName)
            let user = await ajax.getSubmit('/api/users/login',params);
            // console.log(user)
            if(user!=''){
                await context.commit('setLoginUser',user);
                await context.commit("setLoginStatus",true)
            }
        }
    },
    modules:{

    }
})